﻿using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZuesControls.Commons;
using ZuesControls.Controls;
using ZuesControls.Enums;
using ZuesControls.Models;
using ZuesUI.Views;
using static System.Net.Mime.MediaTypeNames;

namespace ZuesUI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : ZSWindow
    {
        private readonly MainWindowViewModel ViewModel;
        private ZSExpander _viewExpander;
        private GcodeWindow GcodeWindow;
        public MainWindow()
        {
            InitializeComponent();

            ViewModel = this.DataContext as MainWindowViewModel;
            this.Loaded += MainWindow_Loaded;
            this.ViewModel.IWidth = 800;
            this.ViewModel.IHeight = 450;
        }



        private async void MyButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = await this.ShowMessageAsync(this,
                "这是一个弹窗", "确定否定取消",
                MessageBoxButton.YesNoCancel);
            if (result == MessageBoxResult.No)
            {

            }
        }

        private async void MyButton_Click_1(object sender, RoutedEventArgs e)
        {
            OperateResult res = await this.ShowProgressBarLoadingAsync(async (CancellationToken) =>
            {
                await Test();
                return new OperateResult();
            });
        }


        public async Task Test()
        {
            for (int i = 0; i < 101; i++)
            {
                await Task.Delay(200);
                this.SetProgressBarValue(i);
            }

        }

        protected override void OnCloseProgressBarCommandExcute(object sender, ExecutedRoutedEventArgs e)
        {
            var jkdojmqwed = 1;
        }


        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {

            GcodeWindow = new GcodeWindow(this.ViewModel);
            GcodeWindow.Show();


        }

        private void Expander_Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }



        private void ZSExpander_ToggleButtonChecked(object sender, RoutedEventArgs e)
        {
            if (_viewExpander == null)
            {
                _viewExpander = sender as ZSExpander;
                return;
            }
            _viewExpander.IsExpanded = false;
            _viewExpander = sender as ZSExpander;

        }

        private void ZSExpander_ToggleButtonUnchecked(object sender, RoutedEventArgs e)
        {
            if (_viewExpander != null)
            {
                _viewExpander = null;
                return;
            }
            Border bor = new Border();

        }




        private void txt_LostFocus(object sender, RoutedEventArgs e)
        {
            var textbox = sender as TextBox;
            textbox.IsReadOnly = true;

        }

        private void txt_KeyDown(object sender, KeyEventArgs e)
        {
            var textbox = sender as TextBox;
            textbox.IsReadOnly = true;

        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // this.border.Visibility = Visibility.Collapsed;
            this.InfoBarModel = new InfoBarModel()
            {
                InfoType = InfoType.Warning,
                Message = "这是警告消息"
            };

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void MyButton_Click_2(object sender, RoutedEventArgs e)
        {

        }

        private void ZSProgressBar_ProgressBarEvent(object sender, ProgressBarEventArgs e)
        {
            var djiqpd = 1;
        }

        private async void MyButton_Click_3(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = await this.ShowMessageAsync(this,
               "这是一个弹窗", "确定否定取消",
               MessageBoxButton.YesNoCancel);
            if (result == MessageBoxResult.No)
            {

            }
        }
        private void colorPalette_ColorChanged(object sender, RoutedPropertyChangedEventArgs<Color> e)
        {
            Debug.WriteLine($"color: {e.NewValue}");
        }

        private void OnStartPicking(object sender, RoutedEventArgs e)
        {
            System.Windows.Application.Current.MainWindow.Hide();
        }

        private void OnCompletedPicked(object sender, RoutedEventArgs e)
        {
            System.Windows.Application.Current.MainWindow.Show();
        }
    }
}